import request from '@/utils/request'

// 简历相关类型定义
export interface ResumeEducation {
    id?: number
    school: string
    major: string
    degree: string
    start_time: string
    end_time: string
    gpa?: number
    description?: string
}

export interface ResumeInternship {
    id?: number
    company: string
    position: string
    start_time: string
    end_time: string
    duration?: string
    description?: string
    achievement?: string
}

export interface ResumeProject {
    id?: number
    project_name: string
    role?: string
    start_time: string
    end_time: string
    technologies?: string
    description?: string
    achievement?: string
    project_url?: string
}

export interface ResumeResearch {
    id?: number
    research_title: string
    project_type?: string
    supervisor?: string
    start_time: string
    end_time: string
    research_field?: string
    description?: string
    achievement?: string
    publications?: string
    research_funding?: string
}

export interface ResumeCompetition {
    id?: number
    competition_name: string
    organization?: string
    competition_time: string
    award?: string
    ranking?: string
    description?: string
    achievement?: string
    certificate?: string
}

export interface ResumeCustomSection {
    id?: number
    section_type: string
    title: string
    content: string
    sort_order: number
}

export interface Resume {
    id?: number
    user_id: number
    avatar?: string
    real_name: string
    student_id?: string
    major?: string
    grade?: string
    degree?: string
    gpa?: number
    phone?: string
    email: string
    personal_advantages?: string
    education_experience?: ResumeEducation[]
    internship_experience?: ResumeInternship[]
    project_experience?: ResumeProject[]
    research_experience?: ResumeResearch[]
    competition_experience?: ResumeCompetition[]
    custom_sections?: ResumeCustomSection[]
    user?: {
        id: number
        username: string
        role: string
    }
}

export interface ResumeMatchRequest {
    skills?: string[]
    major?: string
    limit?: number
}

// API接口
export const getResumeAPI = () => {
    return request.get('/resume')
}

export const createOrUpdateResumeAPI = (data: Resume) => {
    return request.post('/resume', data)
}

export const updateEducationExperienceAPI = (data: ResumeEducation[]) => {
    return request.post('/resume/education', data)
}

export const updateInternshipExperienceAPI = (data: ResumeInternship[]) => {
    return request.post('/resume/internship', data)
}

export const updateProjectExperienceAPI = (data: ResumeProject[]) => {
    return request.post('/resume/project', data)
}

export const updateResearchExperienceAPI = (data: ResumeResearch[]) => {
    return request.post('/resume/research', data)
}

export const updateCompetitionExperienceAPI = (data: ResumeCompetition[]) => {
    return request.post('/resume/competition', data)
}

export const updateCustomSectionsAPI = (data: ResumeCustomSection[]) => {
    return request.post('/resume/custom', data)
}

export const getRandomStudentsAPI = (limit: number = 10) => {
    return request.get('/resume/match/random', { params: { limit } })
}

export const searchStudentsBySkillsAPI = (data: ResumeMatchRequest) => {
    return request.post('/resume/match/search-skills', data)
}

export const searchStudentsByMajorAPI = (major: string, limit: number = 10) => {
    return request.get('/resume/match/search-major', { params: { major, limit } })
}

// 默认头像选项
export const defaultAvatars = [
    { name: '默认男头像', url: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png' },
    { name: '默认女头像', url: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png' },
    { name: '学生头像1', url: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpg.jpeg' },
    { name: '学生头像2', url: 'https://cube.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg' },
]

// 学历选项
export const degreeOptions = [
    { label: '高中', value: 'high_school' },
    { label: '专科', value: 'diploma' },
    { label: '本科', value: 'bachelor' },
    { label: '硕士', value: 'master' },
    { label: '博士', value: 'phd' },
]

// 专业选项
export const majorLabels = [
    { label: '计算机科学与技术', value: 'computer_science' },
    { label: '软件工程', value: 'software_engineering' },
    { label: '电子信息工程', value: 'electronic_information' },
    { label: '网络工程', value: 'network_engineering' },
    { label: '数据科学与大数据技术', value: 'big_data' },
    { label: '人工智能', value: 'artificial_intelligence' },
    { label: '机械工程', value: 'mechanical_engineering' },
    { label: '电气工程', value: 'electrical_engineering' },
    { label: '金融学', value: 'finance' },
    { label: '工商管理', value: 'business_administration' },
    { label: '其他', value: 'other' },
]
